# content/views.py
from django.shortcuts import render, get_object_or_404
from .models import MarkdownPage
import markdown

def page_list(request):
    pages = MarkdownPage.objects.all()
    return render(request, 'content/page_list.html', {'pages': pages})

def page_detail(request, pk):
    page = get_object_or_404(MarkdownPage, pk=pk)
    # 将Markdown转换为HTML
    html_content = markdown.markdown(page.content)
    context = {
        'page': page,
        'html_content': html_content
    }
    return render(request, 'content/page_detail.html', context)
